package com.weihuachao.repair;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.lidroid.xutils.http.RequestParams;
import com.weihuachao.entity.Result;
import com.weihuachao.https.BasicRequestCallBck;
import com.weihuachao.https.XUtils;

/**
 * Created by Virgo on 2016/8/3.
 */
public class AddWorkActivity extends Activity {
    Button goback;
    Button submitWork;
    TextView addworktitle;
    TextView addworktext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        XUtils.init(this);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_addwork);
        goback = (Button) findViewById(R.id.goback);
        submitWork = (Button) findViewById(R.id.submit_work);
        addworktitle = (TextView) findViewById(R.id.addworktitle);
        addworktext = (TextView) findViewById(R.id.addworktext);
        goback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        submitWork.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //有bug
                String title = addworktitle.getText().toString();
                String text = addworktext.getText().toString();
                RequestParams params = new RequestParams();
                params.addBodyParameter("work.uid", String.valueOf(com.weihuachao.app.application.getUid()));
                params.addBodyParameter("work.state", String.valueOf(1));
                params.addBodyParameter("work.title", String.valueOf(title));
                params.addBodyParameter("work.text", String.valueOf(text));
                if (text != null && title != null&&text!=""&&title!="") {
                    XUtils.send(XUtils.ADDWORK, params, new BasicRequestCallBck<Result<Boolean>>() {
                        @Override
                        public void success(Result<Boolean> data) {
                            if (data.state == 1) {
                                Toast.makeText(AddWorkActivity.this, "提交成功！", Toast.LENGTH_SHORT).show();
                                startActivity(new Intent(AddWorkActivity.this, MainActivity.class));
                            }
                        }
                    });
                } else {
                    Toast.makeText(AddWorkActivity.this, "标题或者内容为空！", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

}
